home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / VIVIDUS / VECT.SIT / vect / ifvect.c next >
C/C++ Source or Header  |  1991-10-05  |  4KB  |  253 lines

  1. #include    <math.h>
  2. #include    "vect.h"
  3.  
  4. /*    ======================================================================
  5.  
  6.     IntVector and FixedVector library.
  7.     
  8.     This is part of the vect Vividus Source Code Library.  See the
  9.     extern vect.doc documentation file for usage.  See individual
  10.     routines for routine documentation.
  11.     
  12.     Copyright 1991 by Vividus Consulting.
  13.     
  14.     This is not public domain source code.  You may not copy and
  15.     paste from this source code.  Read your Vividus Licensing
  16.     agreement for details and other restrictions.
  17.  
  18.     ======================================================================    */
  19.  
  20. void
  21. v2fv(
  22.     vector    *v,
  23.     FixedVector    *fv)
  24. /*
  25.     fv = v
  26. */
  27. {
  28. #if    __option(mc68881)
  29.     extended    x, y, z;
  30.     
  31.     x96tox80(&v->x, &x);
  32.     x96tox80(&v->y, &y);
  33.     x96tox80(&v->z, &z);
  34.     fv->x = X2Fix(x);
  35.     fv->y = X2Fix(y);
  36.     fv->z = X2Fix(z);
  37. #else
  38.     extended    x, y, z;
  39.     
  40.     x96tox80(&v->x, &x);
  41.     x96tox80(&v->y, &y);
  42.     x96tox80(&v->z, &z);
  43.     fv->x = X2Fix(x);
  44.     fv->y = X2Fix(y);
  45.     fv->z = X2Fix(z);
  46. #endif
  47. }
  48.  
  49.  
  50. void
  51. fv2v(
  52.     FixedVector    *fv,
  53.     vector    *v)
  54. /*
  55.     v = fv
  56. */
  57. {
  58. #if    __option(mc68881)
  59.     extended    x, y, z;
  60.     
  61.     x = Fix2X(fv->x);
  62.     y = Fix2X(fv->y);
  63.     z = Fix2X(fv->z);
  64.     x80tox96(&x, &v->x);
  65.     x80tox96(&y, &v->y);
  66.     x80tox96(&z, &v->z);
  67. #else
  68.     extended    x, y, z;
  69.     
  70.     x = Fix2X(fv->x);
  71.     y = Fix2X(fv->y);
  72.     z = Fix2X(fv->z);
  73.     x80tox96(&x, &v->x);
  74.     x80tox96(&y, &v->y);
  75.     x80tox96(&z, &v->z);
  76. #endif
  77. }
  78.  
  79.  
  80. void
  81. fv2iv (
  82.     FixedVector    *fv,
  83.     IntVector    *iv)
  84. /*
  85.     iv = fv
  86. */
  87. {
  88.     iv->x = HiWord(fv->x);
  89.     iv->y = HiWord(fv->y);
  90.     iv->z = HiWord(fv->z);
  91. }
  92.     
  93. void
  94. iv2fv (
  95.     IntVector    *iv,
  96.     FixedVector    *fv)
  97. /*
  98.     fv = iv
  99. */
  100. {
  101.     fv->x = Long2Fix((long) iv->x);
  102.     fv->y = Long2Fix((long) iv->y);
  103.     fv->z = Long2Fix((long) iv->z);
  104. }
  105.  
  106. /*    ============================================================    */
  107.  
  108. void
  109. fvcopy (
  110.     FixedVector    *v,
  111.     FixedVector    *vo)
  112. /*
  113.     vo = v
  114. */
  115. {
  116.     vo->x = v->x;
  117.     vo->y = v->y;
  118.     vo->z = v->z;
  119. }
  120.     
  121. void
  122. fvscale (
  123.     Fixed        scalar,
  124.     FixedVector    *v,
  125.     FixedVector    *vo)
  126. /*
  127.     Multiply v by scalar.
  128. */
  129. {
  130.     vo->x = FixMul(v->x, scalar);
  131.     vo->y = FixMul(v->y, scalar);
  132.     vo->z = FixMul(v->z, scalar);
  133. }
  134.     
  135. void
  136. fvvect (
  137.     FixedVector    *a,
  138.     FixedVector    *b,
  139.     FixedVector    *v)
  140. /*
  141.     Find the vector going from point a to point b. 
  142. */
  143. {
  144.     v->x = b->x - a->x;
  145.     v->y = b->y - a->y;
  146.     v->z = b->z - a->z;
  147. }
  148.     
  149. void
  150. fvsub (
  151.     FixedVector    *a,
  152.     FixedVector    *b,
  153.     FixedVector    *v)
  154. /*
  155.     v = a - b
  156. */
  157. {
  158.     v->x = a->x - b->x;
  159.     v->y = a->y - b->y;
  160.     v->z = a->z - b->z;
  161. }
  162.     
  163. void
  164. fvadd (
  165.     FixedVector    *a,
  166.     FixedVector    *b,
  167.     FixedVector    *v)
  168. /*
  169.     v = a + b
  170. */
  171. {
  172.     v->x = a->x + b->x;
  173.     v->y = a->y + b->y;
  174.     v->z = a->z + b->z;
  175.     return;
  176.     
  177.     /*    The following notice may not be removed under any
  178.         circumstance.  See your licensing agreement.        */
  179.     asm {
  180.         dc.b    "ifvect Copyright 1991 Vividus Consulting"
  181.     }
  182. }
  183.  
  184. /*    ============================================================    */
  185.  
  186. void
  187. ivcopy (
  188.     IntVector    *v,
  189.     IntVector    *vo)
  190. /*
  191.     vo = v
  192. */
  193. {
  194.     vo->x = v->x;
  195.     vo->y = v->y;
  196.     vo->z = v->z;
  197. }
  198.  
  199. void
  200. ivscale (
  201.     int            scalar,    
  202.     IntVector    *v,
  203.     IntVector    *vo)
  204. /*
  205.     vo = scalar * v
  206. */
  207. {
  208.     vo->x = v->x * scalar;
  209.     vo->y = v->y * scalar;
  210.     vo->z = v->z * scalar;
  211. }
  212.     
  213. void
  214. ivvect (
  215.     IntVector    *a,
  216.     IntVector    *b,
  217.     IntVector    *v)
  218. /*
  219.     Find the vector going from point a to point b. 
  220. */
  221. {
  222.     v->x = b->x - a->x;
  223.     v->y = b->y - a->y;
  224.     v->z = b->z - a->z;
  225. }
  226.     
  227. void
  228. ivsub (
  229.     IntVector    *a,
  230.     IntVector    *b,
  231.     IntVector    *v)
  232. /*
  233.     v = a - b
  234. */
  235. {
  236.     v->x = a->x - b->x;
  237.     v->y = a->y - b->y;
  238.     v->z = a->z - b->z;
  239. }
  240.     
  241. void
  242. ivadd (
  243.     IntVector    *a,
  244.     IntVector    *b,
  245.     IntVector    *v)
  246. /*
  247.     v = a + b
  248. */
  249. {
  250.     v->x = a->x + b->x;
  251.     v->y = a->y + b->y;
  252.     v->z = a->z + b->z;
  253. }